// Package utils 一个用来记录部分小工具类方法的包
package utils

import (
	"strconv"
	"strings"
)

// StringBuilder 优化的字符串拼接方法
func StringBuilder(p ...string) string {
	var bl int
	for i, s := range p {
		if i == 0 {
			bl = len(s)
		} else {
			bl += len(s)
		}
	}
	var b strings.Builder
	b.Grow(bl)
	for i := 0; i < len(p); i++ {
		b.WriteString(p[i])
	}
	return b.String()
}

// NtoA 数字转字符串
// converts a number(int/uint/float) to a string.
func NtoA(i interface{}) (s string) {
	switch n := i.(type) {
	case string:
		s = i.(string)
	case int:
		s = strconv.Itoa(n)
	case int8:
		s = strconv.Itoa(int(n))
	case int16:
		s = strconv.Itoa(int(n))
	case int32:
		s = strconv.Itoa(int(n))
	case int64:
		s = strconv.FormatInt(n, 10)
	case uint:
		s = strconv.FormatUint(uint64(n), 10)
	case uint8:
		s = strconv.FormatUint(uint64(n), 10)
	case uint16:
		s = strconv.FormatUint(uint64(n), 10)
	case uint32:
		s = strconv.FormatUint(uint64(n), 10)
	case uint64:
		s = strconv.FormatUint(n, 10)
	case float32:
		s = strconv.FormatFloat(float64(n), 'f', -1, 32)
	case float64:
		s = strconv.FormatFloat(n, 'f', -1, 64)
	default:
		s = ""
	}
	return
}
